package TestPojoNetty;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.buffer.DynamicChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;

public class EncodingHandle extends SimpleChannelHandler {

	@Override
	public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
		// TODO Auto-generated method stub
		pojo p = (pojo) e.getMessage();
		ChannelBuffer buffer =  new DynamicChannelBuffer(20);
		buffer.writeInt(p.name.getBytes("UTF-8").length);
		buffer.writeBytes(p.getName().getBytes("UTF-8"));
		buffer.writeInt(p.getAge());
		Channels.write(ctx, e.getFuture(), buffer); 
	}	
}
